package com.shrcl.engineerprocess.domain.impl;

import com.shrcl.engineerprocess.domain.NotificationSender;
import com.shrcl.engineerprocess.domain.TaskNotification;
import com.shrcl.engineerprocess.domain.impl.NotificationImpl;
import com.shrcl.engineerprocess.domain.proxy.TaskNotificationProxy;
import edu.fudan.langlab.domain.task.TSKTask;
import edu.fudan.langlab.domain.task.impl.TSKTaskImpl;
import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.eclipse.xtext.xbase.lib.InputOutput;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.beans.factory.BeanFactory;

@Entity
@DiscriminatorValue("TASKNOTIFICATION_TYPE")
public class TaskNotificationImpl extends NotificationImpl implements TaskNotification {
  public TaskNotificationImpl() {
    super();
  }
  
  private String title;
  
  public String getTitle() {
    return this.title;
  }
  
  public TaskNotification setTitle(final String title) {
    this.title = title;
    return this;			
    
  }
  
  private String body;
  
  public String getBody() {
    return this.body;
  }
  
  public TaskNotification setBody(final String body) {
    this.body = body;
    return this;			
    
  }
  
  @JoinColumn(name = "tskTask_id")
  @ManyToOne(targetEntity = TSKTaskImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private TSKTask tskTask;
  
  public TSKTask getTskTask() {
    return this.tskTask;
  }
  
  public TaskNotification setTskTask(final TSKTask tskTask) {
    this.tskTask = tskTask;
    return this;			
    
  }
  
  public void doNotify() {
    InputOutput.<String>println("============> send TaskNotification invoke");
    BeanFactory _beanFactory = this.getBeanFactory();
    final NotificationSender notificationSender = _beanFactory.<NotificationSender>getBean(NotificationSender.class);
    notificationSender.sendNotification(this);
  }
  
  public void init() {
    this.setNotificationType("TaskNotification");
  }
  
  public static TaskNotification create(final IObjectFactory objectFactory) {
    com.shrcl.engineerprocess.domain.TaskNotification taskNotification = new com.shrcl.engineerprocess.domain.impl.TaskNotificationImpl(
    );
    objectFactory.create(taskNotification);
    return taskNotification;			
    
  }
  
  public static TaskNotification createTaskNotificationImpl(final IObjectFactory objectFactory, final Procedure1<TaskNotification> init) {
    com.shrcl.engineerprocess.domain.TaskNotification taskNotification = new com.shrcl.engineerprocess.domain.impl.TaskNotificationImpl(
    );
    objectFactory.create(taskNotification);
    init.apply(taskNotification);
    
    return taskNotification;			
    
  }
  
  public TaskNotificationProxy toProxy() {
    com.shrcl.engineerprocess.domain.proxy.TaskNotificationProxy proxy = new com.shrcl.engineerprocess.domain.proxy.TaskNotificationProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
